package com.bbs.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bbs.pojo.Category;
import com.bbs.pojo.Result;
import com.bbs.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    /**
     * 获取以tag分组的板块列表
     * @return
     */
    @GetMapping("/group/tag")
    public String groupByTag(){
        return JSON.toJSONString(categoryService.groupByTag());
    }

    /**
     * 获取板块列表
     * @return
     */
    @GetMapping("/list")
    public String list(){
        return JSON.toJSONString(Result.withData(categoryService.list(new QueryWrapper<>())));
    }

    @GetMapping("/{id}")
    public Result<Category> getCategory(@PathVariable("id") String id){
        return categoryService.getCategory(id);
    }
}
